<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@include file="/common/common.jsp"%>
<%@include file="/common/skins/skin0/component.jsp" %>

<%@include file="/OrderMgr/ordercommon.jsp" %>

<h:css href="/css/style1/style-custom.css"/>
<%--
- Author(s): pengweiling
- Date: 2012-07-06 08:57:21
- Description:
--%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>
      直接入住/预订
    </title>
    <script>
      //配置参数
      <% int ic = 0; %>
      gCfg = {
      <l:iterate property="cfg" id="id1">
         <% if (ic > 0){%>
         ,
         <%} %>
         '<b:write property="parameterCode" iterateId="id1"/>':'<b:write property="parameterValue" iterateId="id1"/>'
         <%ic++; %>
      </l:iterate>
      };
      
      //折扣规则
      <%ic=0; %>
      gRules = [
         <l:iterate property="rules" id ="id2">
         <% if (ic > 0){%>
         ,
         <%} %>
         {
           cCategory:'<b:write property="ccategory" iterateId="id2"/>',
           ndaysfrom:<b:write property="ndaysfrom" iterateId="id2"/>,
           ndaysto:<b:write property="ndaysto" iterateId="id2"/>,
           nratediscount:<b:write property="nratediscount" iterateId="id2"/>
         }
         <%ic++; %>
         </l:iterate>
      ];
    </script>    
    
<%
  String ua = request.getHeader( "User-Agent" );
  boolean isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );
  if (isMSIE==true){

%>
<script type="text/javascript" src="OrderMgr/script/json2.js"></script>  
  
<%} %>  
    <script type="text/javascript" src="commonPick/script/utils.js"></script>    
    <script type="text/javascript" src="OrderMgr/script/order.js"></script>
    <script type="text/javascript" src="OrderMgr/script/orderAjax.js"></script>
<style>
   .eos-body-div{
     width:100% !important;
   }
</style>

  </head>
  <body>             
    <e:datasource name="weordertasks" type="entity" path="com.hms.OrderMgr.order.WeOrdertasks" />
    <h:form name="data_form" action="com.hms.OrderMgr.Warkin.flow" method="post" onsubmit="return submitDatacell(this);">
      <h:hidden property="weordertasks/iorderid" />
      <input type="hidden" id="depositSaved" value="N">
      <input type="hidden" name="_eosFlowAction" value="insertSubmit" >
      <h:hiddendata property="criteria" />
      <h:hidden property="page/begin"/>
      <h:hidden property="page/length"/>
      <h:hidden property="page/isCount"/>
      <dataform id= "efa30c85-dbed-4340-a754-267fa9a49981">
          <table align="center" border="0" width="100%" class="form_table">
            <tr>
               <td class="form_label">
                  订单编号
               </td>
              <td colspan="5" style="color:blue">
                <b:write property="weordertasks/corderno"/>
              </td>               
            </tr>
            <tr>
              <td class="form_label">
                预订人
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cbookname" style="width:200px;" validateAttr="allowNull=false"/><font style="color:red">*</font>
              </td>
              <td class="form_label">
                预订人手机
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cbooktel"  style="width:200px;" />
              </td>
              <td class="form_label">
                预定会员
              </td>
              <td colspan="1">
                <w:lookup property="weordertasks/cbookmemberid"  
                          displayProperty="weordertasks/memberName"
                          style="width:200px;" 
                          dialogTitle="选择会员"
                          allowInput="false"
                          lookupUrl="com.hms.commonPick.WeMemberSelect.flow"/>

              </td>
            </tr>
            <tr>
              <td class="form_label">
                是否送机
              </td>
              <td colspan="1">
                <h:switchCheckbox checkedValue="Y" property="weordertasks/bisseeoff" uncheckedValue="N" />
              </td>
              <td class="form_label">
                送机时间
              </td>
              <td colspan="1">
                <w:date property="weordertasks/dseeoffdate" style="width:200px;"  format="yyyy-MM-dd HH:mm:ss" />
              </td>
              <td class="form_label">
                送机目的地
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cseeoffaddress" style="width:200px;"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                客人来源
              </td>
              <td colspan="1">
                <input type="hidden" name="weordertasks/csourcename" value = "WalkIn" />
                直接入住
              </td>
              <td class="form_label">
                来源说明
              </td>
              <td colspan="3">
                <h:text property="weordertasks/csoucedescription" style="width:100%;" />
              </td>
            </tr>            
            <tr>
              <td class="form_label">
                总金额
              </td>
              <td colspan="1">
                <input type="text" id="txtPriceAmt" style="width:200px;" readonly="true"  />
                <input type="hidden" id="txtOriginAmt"/>
                <input type="hidden" id="txtDiscount"/>
                <input type="hidden" id="txtPrepayAmt"/>
                <input type="hidden" id="txtCommision"/>                
                <input type="hidden" name="weordertasks/npaypercent" id="txtPrepayPercent" value="1"/>
              </td>            
              <td class="form_label">
                付款方式
              </td>
              <td colspan="1">
                <d:select property="weordertasks/cpaymenttype" style="width:200px;" nullLabel="请选择" dictTypeId="HMS_PAYMENT_TYPE" />
              </td>
              <td class="form_label">
                付款摘要
              </td>
              <td colspan="1">
                <h:text property="weordertasks/cpaymentdescription" style="width:100%;"/>
              </td>
            </tr>
            <tr>
              <td class="form_label">
                备注
              </td>
              <td colspan="5">
                <h:textarea property="weordertasks/cdescription" style="width:100%;" />
              </td>
            </tr>
            <tr class="form_bottom">
              <td colspan="6">
                <input type="submit" value="保存" class="button" onsubmit="return submitDatacell(this);">
                <input type="button" class="button" onclick="history.go(-1)" value="返回"> 
              </td>
            </tr>
          </table>
      </dataform>
      
      <w:layout height="70%" type="vertical" width="100%">
         <w:layoutPanel height="20%" width="100%">
            <w:layout height="100%" type="horizontal" width="100%">
              <w:layoutPanel width="60%" height="100%"> 
                 <r:datacell height="250" pageSize="1000" entityType="com.hms.OrderMgr.order.WeGres" id="gress" isCount="false" readonly="false" submitXpath="weordertasks/gress" width="100%" xpath="weordertasks/gress">
                   <r:toolbar location="top" tools="edit:add del"/>
                   <r:field fieldName="roomno" label="房号">
                     <w:lookup lookupUrl="com.hms.commonPick.WeRoomSelect.flow"
                               dialogTitle="选择房间"
                               allowInput="false"
                               onReturnFunc="setRoomId"
                     />
                   </r:field>
                   
                   <r:field fieldName="arrorigdate" label="抵店日期" nullText="必须输入" width="126">
                     <w:date format="yyyy-MM-dd HH:mm:ss" />
                   </r:field>
                              
                   <r:field fieldName="deporigdate" label="离店日期" nullText="必须输入" width="126">
                     <w:date format="yyyy-MM-dd HH:mm:ss" />
                   </r:field>
                              
                   <r:field fieldName="daycount" label="房晚数" onRefreshFunc="getDayCount" width="95">
                   </r:field>
                      
                   <r:field fieldName="cstatus" label="状态" onRefreshFunc="getGresStatus" width="95">
                   </r:field>     
                   
           <r:field fieldName="roomarea" label="区域"  width="70">
           </r:field>
           <r:field fieldName="areaname" label="小区"  width="70">
           </r:field>
           <r:field fieldName="buildingno" label="栋号" width="70">
           </r:field>
           <r:field fieldName="roomtype" label="房型" width="70">
           </r:field>   
           
                 </r:datacell>
              </w:layoutPanel>
              
              <w:layoutPanel width="40%" height="100%">
                <r:datacell pageSize="1000" id="grdSchedule" height="250"  width="100%" linkId="gress" linkField="schedules">
                   <r:toolbar location="top" tools="edit:refresh"/>
                   <r:field fieldName="dbusinessdate" label="入住日期"></r:field>
                   <r:field fieldName="nrate" label="房价/晚"></r:field>                                                      
                </r:datacell>                
              </w:layoutPanel>
            </w:layout>
         </w:layoutPanel>
         <w:layoutPanel height="80%" width="100%">         
           <w:tabPanel bodyStyle="" defaultTab="tabEntry" height="100%" id="pgInfo" titleStyle="" width="100%">              
              <w:tabPage cache="true" id="tabEntry" tabType="div" title="入住信息">
                <%@include file="/OrderMgr/EntryInfo.jsp" %>
              </w:tabPage> 
           </w:tabPanel>
         </w:layoutPanel>
      </w:layout>

      
    </h:form>
    <script>
      function submitDatacell(frm) {
      
        //检查客单是否已经收取房费和押金
        if (validateOrder()== false){
          return false;
        }
        var token = "", idx = 1, amt = 0, dp = 0;
        
        if (checkForm(frm)) {
          var dcell = $id('gress'), needrate = false; 
          var curr = dateToString(new Date(), 'yyyy-MM-dd');
          var entities = dcell.dataset.getAlltEntities();
          for(var i = 0; i < entities.length; i++){
            if (entities[i].status == Entity.STATUS_DELT || entities[i].status == Entity.STATUS_HIDDEN){
              continue;
            }
            
            if (entities[i].getProperty("cstatus") == "R"){
               var vd = dateToString(stringToDate(entities[i].getProperty("arrorigdate")), 'yyyy-MM-dd');
               if (vd == curr){
                 if (confirm("房号" + entities[i].getProperty("roomno") + "预计抵店日期为今天，是否要入住?")){//检查入住
                    //TODO:执行入住检查，如果通过就设置客单表中入住信息
                    $id("gress").selectRow($id("gress").getRowAt(idx-1));
                    return false;
                 }
               }
            }
            
            if (!entities[i].getProperty("bills")){
              needrate = true;
            }
            amt = getLineAmt(null, entities[i], 0, 0, null, "nrate");
            dp = Math.round(amt * gDepositRate*10000)/10000;
            token += "&gres[" + idx + "]/rm=" + entities[i].getProperty("roomno") + "&gres[" + idx + "]/rt=" + amt + "&gres[" + idx + "]/dm=" + dp + "&gres[" + idx + "]/key=" +  entities[i].getProperty("localkey");
            idx++;
          }
          
          //检查收取房费
          if (needrate == true){
             //TODO:收取房费和押金，通过后产生账单;
             showModalCenter("com.hms.OrderMgr.GetWalkinDeposit.flow?a=1" + token,
                   null,
                   function(args){
                     if (!args){return;}
                     for(var i  = 0; i < args.length; i++){
                        var tmp = [{
                            iitemid:1,
                            citemcode:"CASH",
                            citemdesc:'现金',
                            ncredit:args[i].getProperty("rt"),
                            dbusinessdate:dateToString(toBusinessDate(new Date())),
                            cremarks:args[i].getProperty("remark"),
                            cdescription:args[i].getProperty("rp"),
                            ccategory:"C",
                            cstatus:'O'
                        },{
                            iitemid:2,
                            citemcode:"DEPOSIT",
                            citemdesc:'押金',
                            ncredit:args[i].getProperty("dm"),
                            dbusinessdate:dateToString(toBusinessDate(new Date())),
                            cremarks:args[i].getProperty("remark"),
                            cdescription:args[i].getProperty("dp"),
                            ccategory:"C",
                            cstatus:'O'                            
                        }];
                        
                        var t= getGressEntity(args[i].getProperty("key"));
                        t.setPropertyByFieldName("bills", Json2Dataset(tmp));
                     }
                     dcell.submitAllByHidden();
                     $name("data_form").submit();
                   },
                   650,
                   380,
                   "收取房费和押金"
             );             
             return false;
          }else{
            dcell.submitAllByHidden();
            return true;
          }
        }

        return false;
      }
      
      $id("gress").afterAdd = synGresAdd;
      $id("gress").afterDel = afterGressDelete;
      $id("gress").afterEdit = synGresEdit;
      $id("gress").afterSelectRow = showGressDetail;
      
      //line grid event
      $id("grdSchedule").afterAdd = sumAmount;
      $id("grdSchedule").afterDel = sumAmount;
      $id("grdSchedule").afterEdit = sumAmount;

      <%
        if (isMSIE==true){
       %>
         $id("btnCheckIn").attachEvent("onclick", function(){
           if (!canCheckIn($id("gress").getActiveEntity())){
             return;
           } 
           writeback(true)
           gCheckInChanged = false;
         });
       <%}else{ %>
         $id("btnCheckIn").addEventListener("click", function(){
           if (!canCheckIn($id("gress").getActiveEntity())){
             return;
           } 
           writeback(true); 
           gCheckInChanged = false;
         });       
       <%} %>
       $id("gress").loadData = function () {
         if (this.beforeLoadData() === false) return;
         if (this.dataXML == "<json/>") return;
         if (!this.linkId && !this.queryAction && this.xpath) {
           var xmlZone = document.getElementById(this.id + "_xml");
           this.dataXML = xmlZone ? xmlZone.innerHTML : null
         } else if (this.linkId && this.linkId.indexOf("xml:") == 0) {
           xmlZone = document.getElementById(this.linkId.substring(4));
           this.dataXML = xmlZone ? xmlZone.innerHTML : null
         } else if (this.linkId && this.isFirstLoad) {
           this.isFirstLoad = false;
           return
         }
         var xmlDom;
         if (this.dataXML && this.dataXML !== "<json/>") {
            this.dataset = Dataset.create(this.dataXML, this.xpath);
            xmlDom = createXmlDom();
            xmlDom.loadXML(this.dataXML);
            var pagecond = xmlDom.selectSingleNode("/root/data/page");
            this.freshPagePilot(pagecond);
            
      <l:notEmpty property="room/iroomid">
      //如果是直接入住
      this.dataset.addBlankEntity();
      var ety = this.dataset.values[0];
      ety.setPropertyByFieldName("iroomid", '<b:write property="room/iroomid"/>');
      ety.setPropertyByFieldName("roomno", '<b:write property="room/croomno"/>');
      ety.setPropertyByFieldName("arrorigdate", dateToString(new Date(), 'yyyy-MM-dd HH:mm:ss'));
      ety.setPropertyByFieldName("deporigdate", dateToString(new Date((new Date()).getTime() + (24 * 60 * 60 * 1000)), 'yyyy-MM-dd') + " 12:00:00");  
      ety.setPropertyByFieldName("cstatus", "R");  
      initGress();                   
      gGress[0].inited = false;
      </l:notEmpty>
                  
            return
         }
         if (this.onLoadData() !== false) {
           if (!this.queryAction) return;
           var ajax = new HideSubmit(this.queryAction), param = this.getQueryForm();
           if (this.queryParam) param += this.queryParam;
           if (this.pageParam) param += this.pageParam;
           if (this.initParamFunc) {
            try {
                param += eval(this.initParamFunc + "()")
            } catch(e) {
                $handle(e)
            }
           }
           if (param == "") param = null;
           if (this.paramFormId) {
            var form = $id(this.paramFormId);
            if (form) for (var i = 0; i < form.elements.length; i++) {
                var elem = form.elements[i];
                if (elem.name) ajax.addParam(elem.name, getElementValue(elem))
            }
        }
        if (this.paramList) for (i = 0; i < this.paramList.length; i++) {
            elem = this.paramList[i];
            if (elem) ajax.addParam(elem.key, elem.value)
        }
        ajax.loadData(param);
        xmlDom = ajax.retDom;
        this.dataset = Dataset.create(xmlDom, this.xpath, this.getSubmitXpath());
        pagecond = xmlDom.selectSingleNode("/root/data/page");
        this.freshPagePilot(pagecond);
        this.afterLoadData(ajax)
    }
};

      function setRoomId(args){         
         var ety = $id("gress").activeEntity;
         ety.setPropertyByFieldName("iroomid", args[0]);
         args[0] = args[1];
         ety.setPropertyByFieldName("roomtype", args[5]);
         ety.setPropertyByFieldName("buildingno", args[2]);                  
         ety.setPropertyByFieldName("areaname", args[3]);
         ety.setPropertyByFieldName("roomarea", args[4]);
                  
      }

      //开始刷新
      gressRefreshQueue();
      
      <l:equal property="_eosLastAccessAction" targetValue="insert">
        $id("txtPrepayPercent").value = gCfg.PREPAY_PERCENT + "";
      </l:equal>
      
      function getWalkinDepositAndRate(){//检查是否已经收取房费和押金
      }
      
      CalendarEditor.refreshTime = function (A) {
        if (CalendarEditor.showTime) {
          A.setHours(CalendarEditor.timeSelect.getHours());
          A.setMinutes(CalendarEditor.timeSelect.getMinutes());
          A.setSeconds("00")
        }
        return A
      };
      
      CalendarEditor.showEditor = function () {
            if (CalendarEditor.showTime) {
                CalendarEditor.timeContainer.style.display = "";
                CalendarEditor.okBtn.style.display = "";
                if (isFF) {
                    CalendarEditor.container.style.height = "226px";
                    CalendarEditor.container.firstChild.style.height = "226px"
                }
            } else {
                CalendarEditor.timeContainer.style.display = "none";
                CalendarEditor.okBtn.style.display = "none";
                if (isFF) {
                    CalendarEditor.container.style.height = "200px";
                    CalendarEditor.container.firstChild.style.height = "200px"
                }
            }
            CalendarEditor.initCalendarEvent();
            
            if (!CalendarEditor.value){
               var field = $id("gress").activeField;
               if (field && field.fieldName == "deporigdate"){
                 CalendarEditor.value = dateToString(new Date(), 'yyyy-MM-dd') + " 12:00:00";
               }
            }
            CalendarEditor.freshDate(CalendarEditor.value);
            CalendarEditor.freshTimeComp();
            CalendarEditor.showStatus = true;
            CalendarEditor.container.style.display = "";
            var A = $id("_eos_calendar_editor_container", CalendarEditor.doc);
            initShadow(A, CalendarEditor.doc)
      };
      
    </script>
  </body>
  

  
</html>

